package com.movitech.mobile.cz.base.supplier.service.impl;

import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.common.util.StringUtils;
import com.movitech.mobile.cz.base.common.utils.IdGen;
import com.movitech.mobile.cz.base.supplier.entity.SEvaluationPerson;
import com.movitech.mobile.cz.base.supplier.entity.ext.ExtSEvaluationPerson;
import com.movitech.mobile.cz.base.supplier.mapper.SEvaluationPersonMapper;
import com.movitech.mobile.cz.base.supplier.mapper.ext.ExtSEvaluationPersonMapper;
import com.movitech.mobile.cz.base.supplier.service.SEvaluationPersonService;
import com.movitech.mobile.cz.base.util.UserUtils;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 供方评估--供方评估人员 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@Service("sEvaluationPersonService")
@Transactional
public class SEvaluationPersonServiceImpl extends ServiceImpl<SEvaluationPersonMapper, SEvaluationPerson> implements SEvaluationPersonService {

    @Autowired
    private SEvaluationPersonMapper sEvaluationPersonMapper;
    @Autowired
    private ExtSEvaluationPersonMapper extSEvaluationPersonMapper;

    @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackForClassName = { "RuntimeException", "Exception" })
    @Override
    public boolean updateSEvaluationPerson(String evaluationId,List<ExtSEvaluationPerson> extSEvaluationPersonList) {
    	
        if(extSEvaluationPersonList != null && StringUtils.isNotBlank(evaluationId)){
        	
        	extSEvaluationPersonMapper.deleteSEvaluationPersonByEvaluationId(evaluationId);
        	
            int i = 0;
            for(ExtSEvaluationPerson template : extSEvaluationPersonList){
                SEvaluationPerson sEvaluationPerson = new SEvaluationPerson();
                sEvaluationPerson.setEvaluationId(evaluationId);
                sEvaluationPerson.setDepartmentId(template.getDepartmentId());
                sEvaluationPerson.setUserId(template.getUserId());
                sEvaluationPerson.setBaseFeilds(UserUtils.getCurrentUserId(), null, CommonConstants.NO_INTEGER, true);
                i += sEvaluationPersonMapper.insert(sEvaluationPerson);
            }
            return i == extSEvaluationPersonList.size();
        }
        return false;
    }
}
